<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="private">
		<meta content="telephone=no,email=no" name="format-detection">
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta http-equiv="Access-Control-Allow-Origin" content="*" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>提现密码管理</title>
		
		<link rel="stylesheet" href="./css/bootstrap/css/bootstrap.css">
		<link rel="stylesheet" href="./css/common/style.css">
		<script src="./js/lib/rem.js"></script>
		<script src="./js/lib/jquery-3.3.1.min.js"></script>
		<script src="./js/lib/common.js"></script>
	</head>
	<style>
		.password{width:100%;height:100%;background:#fff;position:fixed;}
		.head{width:100%;height:1rem;line-height:1rem;text-align:center;background:#0c5dac;position:relative}
		.head-back{width:20%;height:1rem;position:absolute;left:0;top:0;display:flex;flex-direction:row;align-items:center;justify-content:center;}
		.head-back > i.back{width:0.4rem;height:0.4rem;display:inline-block;background:url('./img/icons/left.png') no-repeat;background-size:0.4rem;}
		.head-back > span{font-size:0.3rem;color:#fff;}
		.head-title{width:100%;height:1rem;line-height:1rem;text-align:center;background:#0c5dac;}
		.head-title > span{font-size:0.34rem;color:#fff;}
		
		.update-password{width:92%;height:calc(100% - 1rem);margin:0.3rem 4% 0;}
		.password-input{width:100%;height:0.8rem;margin-top:0.2rem;display:flex;flex-direction:row;border-bottom:0.02rem solid #ccc;}
		.password-input > span{width:35%;height:0.8rem;line-height:0.8rem;text-align:center;font-size:0.26rem;color:#999;}
		.password-input > input{width:65%;height:0.78rem;padding:0 3%;border:none;outline:none;font-size:0.28rem;color:#222;-webkit-text-security:disc;text-security:disc;}
		
		.password-notice{width:100%;height:0.7rem;line-height:0.8rem;padding-left:3%;}
		.password-notice > span{font-size:0.28rem;color:#f00;}
		
		.update-btn{width:100%;height:0.8rem;margin-top:0.3rem;text-align:center;}
		.update-btn > button{width:80%;height:0.8rem;background:#217bd1;outline:none;border:none;color:#fff;font-size:0.32rem;border-radius:0.1rem;}
		
		
		.infor-modal{display:none;position:fixed;width:100%;height:100%;background:rgba(0,0,0,0.5);}
		.infor-contain{width:85%;height:auto;background:#fff;margin:45% auto 0;border-radius:0.2rem;}
		
		.informodal-title{width:100%;height:1rem;border-bottom:0.01rem solid #ccc;position:relative;}
		.modal-title{width:100%;height:1rem;line-height:1rem;text-align:center;}
		.modal-title > span{font-size:0.3rem;color:#222;}
		
		.inforModal-content{width:100%;height:3rem;display:flex;flex-direction:column;justify-content:center;align-items:center;}
		.inforModal-content > span{font-size:0.3rem;color:#222;margin-bottom:1rem;}
		
	</style>
	<body>
		<div class="password">
			<div class="head">
				<div class="head-back" onClick='javascript:history.go(-1);'>
					<i class="back"></i>
					<span>返回</span>
				</div>
				<div class="head-title">
					<span>提现密码管理</span>
				</div>
			</div>
			
			<div class="update-password">
				<div class="password-input">
					<span>当前交易密码：</span>
					<input type="number" id="oldpwd" placeholder="请输入当前交易密码">
				</div>
				<div class="password-input">
					<span>新的交易密码：</span>
					<input type="number" id="newpwd" placeholder="请输入新的交易密码">
				</div>
				<div class="password-input">
					<span>确认交易密码：</span>
					<input type="number" id="confirmpwd" placeholder="确认交易密码">
				</div>
				
				<div class="password-notice" id="errorMsg">
					<span>注：初始密码为：123456</span>
				</div>
				
				<div class="update-btn">
					<button type="button" id="changepwdBtn">保存</button>
				</div>
			</div>

		</div>
		
		<!-- putforward modal -->
		<div class="infor-modal" id="pwdModal">
			<div class="infor-contain">
				<div class="informodal-title">
					<div class="modal-title">
						<span>消息提示</span>
					</div>
				</div>
				<div class="inforModal-content">
					<span id="pwdContext"></span>
				</div>
			</div>
		</div>
		
		<div id="taskdiv"></div>
		
		<!-- putforward modal -->
		<div class="infor-modal" id="inforModal">
			<div class="infor-inner">
				<div class="infor-contain">
					<div class="informodal-title">
						<div class="modal-title">
							<span>试玩助手</span>
						</div>
					</div>
					<div class="inforModal-content">
						<span id="inforContextTitle"></span>
						<span id="inforContext"></span>
					</div>
				</div>
			</div>
		</div>
		
		<script src="./js/sendtask.js?v=1043"></script>
		<script type="text/javascript" src="./js/lib/map/maps.js"></script>
		<script src="./js/lib/mui/mui.min.js"></script>
		
		<script>
			$(function(){
				
				var taskstate = localStorage.getItem('taskstate');
				if(taskstate === "true"){
					//after five minutes send task start
					setTimeSendTaskStart();
				}
				
				var urlip = localStorage.getItem('urlip');
				var url = 'http://'+ urlip +':8080/platform-web/';
				var userid = localStorage.getItem('userid');
				
				//check password code
				checkpwd('#oldpwd');
				checkpwd('#newpwd');
				checkpwd('#confirmpwd');
				
				//submit change password
				changePwdSubmit(url,userid);
				
				//check password code
				function checkpwd(obj){
					$(obj).on('keyup',function(){
						var curVal = $(this).val();
						var reg = /^[0-9]*$/;
						var endVal = '';
						for(var i=0;i<=curVal.length;i++){
							if( reg.test(curVal[i]) ){
								if(endVal.length < 6){
									endVal += curVal[i];
									$('#errorMsg > span').text('')
								}else{
									$('#errorMsg > span').text('交易密码为六位数字')
								}
							}
						}
						$(this).val(endVal);
						return false;
					})
					
					$(obj).on('blur',function(){
						var curVal = $(this).val();
						
						if(curVal.length < 6){
							$('#errorMsg > span').text('交易密码为六位数字')
						}else{
							$('#errorMsg > span').text('')
						}
					})
				}
				
				//submit change password
				function changePwdSubmit(url,userid){
					$('#changepwdBtn').click(function(){
						var oldpwd = $('#oldpwd').val();
						var newpwd = $('#newpwd').val()
						var confirmpwd = $('#confirmpwd').val()
						if(oldpwd){
							if(oldpwd.length < 6){
								$('#errorMsg > span').text('当前交易密码为六位数字')
							}else{
								$('#errorMsg > span').text('')
								if(newpwd){
									if(newpwd.length < 6){
										$('#errorMsg > span').text('新的交易密码为六位数字')
									}else{
										$('#errorMsg > span').text('')
										if(confirmpwd){
											if(confirmpwd.length < 6){
												$('#errorMsg > span').text('确认交易密码为六位数字')
											}else{
												$('#errorMsg > span').text('')
												if(newpwd == confirmpwd){
													if(userid){
														$.ajax({
															type:'POST',
															url:url+'user/updatePassword',
															dataType:'json',
															data:{
																id:userid,
																oldPassword:oldpwd,
																newPassword:confirmpwd
															},
															success:function(data){
																if(data.code === 403){
																	location.href = './login.html'
																}else if(data.code === 404){
																	alert('设备被锁')
																}else if(data.code === 5000 ){
																	$('#pwdModal').show();
																	$('#pwdContext').text('交易密码修改成功');
																	
																	setTimeout(function(){
																		$('#pwdModal').hide();
																		location.href = "./person.html"
																	},2000)
																	
																}else if(data.code === 5001 ){
																	$('#pwdModal').show();
																	$('#pwdContext').text('当前交易密码错误');
																	
																	setTimeout(function(){
																		$('#pwdModal').hide();
																	},2000)
																	
																}
															}
														})
													}else{
														setTimeout(function(){
															location.href = './login.html'
														},1500)
													}
												}else{
													$('#errorMsg > span').text('两次密码输入不一致')
												}
											}
										}else{
											$('#errorMsg > span').text('确认密码不能为空')
										}
									}
								}else{
									$('#errorMsg > span').text('新密码不能为空')
								}
							}
						}else{
							$('#errorMsg > span').text('当前交易密码不能为空')
						}
					})
					
				}
				
			});
		</script>
	</body>
</html>

